<?php
/**
 * Main loop for displaying blog posts
 *
 * @package ClassiPress
 * @author AppThemes
 *
 */
?>

<?php //appthemes_before_blog_loop(); ?>

<?php if ( have_posts() ) : ?>

    <?php while ( have_posts() ) : the_post() ?>
    
        <?php appthemes_before_blog_post(); ?>

        <div <?php post_class('shadowblock_out'); ?> id="post-<?php the_ID(); ?>">

            <div class="shadowblock">

                <?php appthemes_before_blog_post_title(); ?>

                <h3 class="single blog">
                    <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                    <?php 
                         if (is_user_logged_in()) :
                            if (current_user_can('manage_options')) {
                                //edit_post_link(__('Sửa bài viết', APP_TD), '<p class="edit">', '</p>', $post->ID);
                                $url = CP_POST_NEW_URL ;
                                $url .= "&post_id=".$post->ID ;
                                //$url .= "&"
//                                echo '<p class="edit">
//                                        <a class="post-edit-link" href="'.$url.'" title="Sửa bài viết">Sửa bài viết</a>
//                                    </p>';
                            } 
                            // elseif ($cp_options->ad_edit && $post->post_author == $current_user->ID) {
                            //     $edit_link = add_query_arg('aid', $post->ID, CP_EDIT_URL);
                            //     echo '<p class="edit"><a class="post-edit-link" href="' . $edit_link . '" title="' . __('Edit Ad', APP_TD) . '">' . __('Edit Ad', APP_TD) . '</a></p>';
                            // }
                        endif;
                    ?>
                    <!-- <a href="<?php echo "#" ?>" rel="bookmark" title="<?php the_title(); ?>"><?php echo "edit" ?></a> -->
                </h3>
                
                <?php appthemes_after_blog_post_title(); ?> 

                <?php // hack needed for "<!-- more -->" to work with templates
                    global $more;
                    $more = 0;
                ?>
                
                <?php appthemes_before_blog_post_content(); ?>
                
                <div class="entry-content">

                    <?php if ( has_post_thumbnail() ) the_post_thumbnail('blog-thumbnail'); ?>


                    <?php 
//                    the_content( '<p>' . __( 'Continue reading &raquo;', APP_TD ) . '</p>' );
                    $content = get_the_content();
                    $content =substr(strip_tags($content), 0, 200); 
                    $split = explode(" ", $content);
                    $lastWord =  $split[count($split)-1];
                    echo str_replace($lastWord,"...",$content);                                                           
                    ?>

                    <?php 
//                                    $cont = get_the_content();
//                                    $cont = apply_filters('the_content', $cont);
//                                    $cont = str_replace(']]>', ']]&gt;', $cont);
//                                    $cont = strip_tags($cont,"<p>");
//                                    if(strlen($cont) > 200)
//                                        $cont = substr ($cont,0,200)."...";
//                                    echo $cont;
                    ?>

                    
                </div>    
                
                <?php appthemes_after_blog_post_content(); ?>

            </div><!-- #shadowblock -->

        </div><!-- #shadowblock_out -->
        
        <?php appthemes_after_blog_post(); ?>

    <?php endwhile; ?>
    
        <?php appthemes_after_blog_endwhile(); ?>

<?php else: ?>
    
    <?php appthemes_blog_loop_else(); ?>

<?php endif; ?>

<?php appthemes_after_blog_loop(); ?>
